<include file="Public:head" title='店铺详情' />
<script src="__PUBLIC__/js/Jquery/validate.js"></script>
<script type="text/javascript">
    $(function() {

        jQuery.validator.addMethod("checkSalesDonate", function(value, element) {
            if ($('#donate').prop("checked") == true) {
                var sales_donate = $('#sales_donate').val();
                if (sales_donate != '') {
                    return  true;
                } else {
                    return  false;
                }
            } else {
                return  true;
            }
        });
        jQuery.validator.addMethod("checkSalesFull", function(value, element) {
            if ($('#cut').prop("checked") == true) {
                var full = parseInt($('#sales_full').val());
                if (full > 0) {
                    return  true;
                } else {
                    return  false;
                }
            } else {
                return  true;
            }
        });
        jQuery.validator.addMethod("checkSalesCutValue", function(value, element) {
            if ($('#cut').prop("checked") == true) {
                var full = parseInt($('#sales_full').val());
                if (full > 0) {

                    var cut = parseInt($('#sales_cut').val());
                    if (full > 0 && cut > 0) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return true;
                }
            } else {
                return  true;
            }
        });
        jQuery.validator.addMethod("checkSalesCut", function(value, element) {
            if ($('#cut').prop("checked") == true) {
                var full = parseInt($('#sales_full').val());
                if (full > 0) {
                    var cut = parseInt($('#sales_cut').val());
                    if (full > 0 && cut > 0 && cut < full) {
                        return  true;
                    } else {
                        return false;
                    }
                } else {
                    return true;
                }
            } else {
                return  true;
            }
        });
        checkCircles($("input[name=choseAllArea]"));
        jQuery.validator.addMethod("isPhone", function(value, element) {
            var length = value.length;
            var mobile = /^1[3,5,8]\d{9}$/;
            if ($("input[name=is_check]:checked").val() == 1) {
                return (length == 11 && mobile.exec(value)) ? true : false;
            } else {
                return true;
            }
        });
        jQuery.validator.addMethod("checkArea", function(value, element) {

            if ($("input[name=choseAllArea]").prop("checked") == "checked") {
                return true;
            } else {
                if ($('.areas').children(".g-input-selectbox:last").children("select").val() == '') {
                    return false;
                } else {
                    return true;
                }
            }
        });
        $("#form").validate({
            errorPlacement: function(error, element) {
                var error_td = element.parent('td');
                error_td.find('label.error').hide();
                error_td.append(error);
            },
            rules: {
                name: {
                    required: true,
                    maxlength: 30
                },
                email: {
                    email: true
                },
                phone: {
                    isPhone: true
                },
                area_1: {
                    checkArea: true
                },
                sales_cut: {
                    checkSalesCutValue: true,
                    checkSalesCut: true

                },
                sales_full: {
                    checkSalesFull: true
                },
                sales_donate: {
                    checkSalesDonate: true
                },
                star: {
                    min: 1,
                    max: 10
                }

            },
            messages: {
                name: {
                    required: '店铺名称不能为空',
                    maxlength: '店铺名称不能超过30个字符'
                },
                email: {
                    email: '电子邮箱格式有误'
                },
                phone: {
                    isPhone: "您的店已经开启了,请输入有效的手机号码"
                },
                area_1: {
                    checkArea: "请选择地址"
                },
                sales_cut: {
                    checkSalesCutValue: "减价必须大于0",
                    checkSalesCut: "减价不能大于等于满价"
                },
                sales_full: {
                    checkSalesFull: "满价必须大于0"
                },
                sales_donate: {
                    checkSalesDonate: "赠送内容不能为空"
                },
                star: {
                    min: "最小星级为1",
                    max: "最大星级为10",
                }

            }
        });
    });
</script>
<script>
    function checkForm() {
        var startTime = parseInt($("#startHour").val()) * 60 + parseInt($("#startMinute").val());
        var endtime = parseInt($("#endHour").val()) * 60 + parseInt($("#endMinute").val());
        var addTimes = $('#addTimes').css("display");
        if (addTimes == 'block') {
            var startTime2 = parseInt($("#startHour2").val()) * 60 + parseInt($("#startMinute2").val());
            var endtime2 = parseInt($("#endHour2").val()) * 60 + parseInt($("#endMinute2").val());

            if (startTime2 > endtime2) {
                alert("开始时间不能大于结束时间！");
                return false;
            }
        }
        if (startTime > endtime) {
            alert("开始时间2不能大于结束时间2！");
            return false;
        }
        var business_time = '';
        $('#td_business_time').find("select").each(function(k) {
            if (k == 7) {
                business_time += $(this).val()
            } else {
                business_time += $(this).val() + ",";
            }
        })
        $("#business_time").val(business_time);
        if ($("input[name=choseAllArea]").prop("checked") == false) {
            var i = 0;
            var arr = [];
            $('.areas').each(function(k) {
                var circle = $(this).find('select:last').val();
                if (circle == '') {
                    i++;
                } else {
                    arr.push(circle);
                }

            })
            if (i > 0) {
                alert("请选择具体地址！");
                return false
            }
            $("input[name=circles]").val(arr.join(','))
        }

    }
    function addTimes(obj) {
        if (obj.text() == '+增加时间段') {
            obj.text('-去除时间段');
            $('#addTimes').show();
            $('#addTimes').find("select").val(0)
        } else {
            obj.text('+增加时间段');
            $('#addTimes').hide();
        }
    }
    function addAddr() {
        var areas = $('.areas').eq(0).clone();
        var del = "";
        $('#td_areas').append("<div class='cl'></div>");
        $('#td_areas').append(areas);
        $('#td_areas').append("<a onclick='delAddr($(this))' style='float:left'>&nbsp;删除</a>");
    }
    function delAddr(obj) {
        obj.prev("p.areas").remove();
        obj.prev(".cl").remove();
        obj.remove();
    }
    function checkCircles(obj) {
        if (obj.prop("checked") == true) {
            obj.parent("p").nextAll().hide();
        } else {
            obj.parent("p").nextAll().show();
        }
    }
</script>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <include file="Public:left" />
        <div class="main-content">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="__APP__/{$Think.MODULE_NAME}">首页</a></li>
                    <li><a href="{:U('Shop/lists')}">店铺管理</a></li>
                    <li class="active">店铺{$Think.get.id|getPageType}</li>
                </ul>
            </div>
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-xs-12">
                                <h3 class="header smaller lighter blue">店铺{$Think.get.id|getPageType}</h3>

                                <form action="{:U('Shop/detail_post')}" method="POST" id="form" onsubmit="return checkForm()" enctype="multipart/form-data" >
                                    <table class="table table_detail">
                                        <tbody>
                                            <tr>
                                                <td class="td_left">店铺名称:</td>
                                                <td>
                                                    <input name="name" type="text" class="common_txt"  value="{$detail.name}" autocomplete="off"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="td_left">餐式分类:</td>
                                                <td>
                                                        <select name="dish_type" id="dish_type">
                                                            <foreach name="dish_types" item="row">
                                                                <option value="{$row.id}"<if condition="$row.id eq $detail['dish_type']">selected</if>>{$row.name}</option>
                                                            </foreach>
                                                        </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="td_left">上传图片:</td>
                                                <td>
                                                    <input name="logo" type="file" id="logo" />
                                                </td>
                                            </tr>
                                        <if condition="$detail.id gt 0">
                                            <tr>
                                                <td class="td_left"></td>
                                                <td>
                                                    <img src="{$detail.logo|getShopLogo=###,43}"/>
                                                </td>
                                            </tr>
                                        </if>
                                        <tr>
                                            <td class="td_left">商圈:</td>
                                            <td id="td_areas">
                                                <p>
                                                    <input type="checkbox" autocomplete="off" name="choseAllArea" onclick="checkCircles($(this))" 
                                        <if condition="$detail.circles eq 0">checked</if>>
                                        所有地区
                                        </p>
                                        <empty name="circles" item="row">

                                            <p style="margin:2px 0;float:left" class="areas"> {$Think.get.searchId|getAreaSelect=###,3}</p> <a onclick="addAddr()" style="float:left">+增加地址</a>
                                            <div class="cl"></div>
                                            <else/>
                                            <foreach name="circles" key="key" item="row">
                                                <div class="cl"></div>
                                                <if condition="$key eq 0">
                                                    <p style="margin:2px 0;float:left" class="areas">{$row|getAreaSelect=###,3}</p>
                                                    <a onclick="addAddr()" style="float:left">+增加地址</a>

                                                    <else/>
                                                    <p style="margin:2px 0;float:left" class="areas">{$row|getAreaSelect=###,3}</p>
                                                    <a onclick='delAddr($(this))' style='float:left'>&nbsp;删除</a>
                                                </if>

                                            </foreach>

                                        </empty>
                                        </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">商家星级:</td>
                                            <td>
                                                <input name="star" type="text" class="common_txt" style="width:120px;" value="{$detail.star}" autocomplete="off" /> 星
                                                <span class="orange">范围1-10星</span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">公告:</td>
                                            <td>
                                                <textarea  name="announce" style="width:410px;height:50px;">{$detail.announce}</textarea>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">商家地址:</td>
                                            <td>
                                                <textarea  name="addr" id="addr" style="width:410px;height:50px;">{$detail.addr}</textarea>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">手机:</td>
                                            <td>
                                                <input name="phone" type="text" class="common_txt" style="width:150px;"value="{$detail.phone}" autocomplete="off" /> 
                                        <input name="is_start_phone" type="checkbox" value="1" autocomplete="off" <if condition="$detail.is_start_phone eq 1">checked</if>>
                                        <span class="orange">接受短信</span>
                                        </td>
                                        </tr>
                                        <if condition="$email.is_start eq 1">
                                            <tr>
                                                <td class="td_left">邮箱:</td>
                                                <td>
                                                    <input name="email" type="text" class="common_txt" style="width:150px;"value="{$detail.email}" autocomplete="off" /> 
                                            <input name="is_start_email" type="checkbox" value="1" autocomplete="off" <if condition="$detail.is_start_email eq 1">checked</if>>
                                            <span class="orange">接受邮件</span>
                                            </td>
                                            </tr>
                                        </if>
                                        <tr>
                                            <td class="td_left">营销活动</td>
                                            <td style="text-align: left">
                                                <input type="checkbox" value="1" autocomplete="off" name="sales[]" id="cut" {$detail.sales|getChecked=###,1}>
                                                <img  src="__PUBLIC__/images/jian.png">
                                                网上订餐满<input type="text" name="sales_full" id="sales_full" value="{$detail.sales_full}" autocomplete="off" style="width:40px;">元减<input type="text" name="sales_cut" id="sales_cut" value="{$detail.sales_cut}" autocomplete="off" style="width:40px;">元
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left"></td>
                                            <td style="text-align: left">
                                                <input type="checkbox" value="2" autocomplete="off" name="sales[]"  {$detail.sales|getChecked=###,2}>
                                                <img  src="__PUBLIC__/images/pei.png">
                                                该餐厅参加超时赔付活动，送餐时间超过90分钟，打9折！雨雪天气除外！
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left"></td>
                                            <td style="text-align: left">
                                                <input type="checkbox" value="3" autocomplete="off" name="sales[]"  {$detail.sales|getChecked=###,3}>
                                                <img  src="__PUBLIC__/images/fapiao.png"/>
                                                该餐厅支持开发票，开票订单金额最低50元，请在下单时于订餐备注中填好发票抬头
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left"></td>
                                            <td style="text-align: left">
                                                <input type="checkbox" value="4" autocomplete="off" name="sales[]"  {$detail.sales|getChecked=###,4}>
                                                <img  src="__PUBLIC__/images/quan.png"/>
                                                可使用纸质抵价券，每个订单限使用一张，不与其它优惠同时使用
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left"></td>
                                            <td style="text-align: left">
                                                <input type="checkbox" id="donate" value="5" autocomplete="off" name="sales[]"  {$detail.sales|getChecked=###,5}>
                                                <img  src="__PUBLIC__/images/zeng.png"/>
                                                <input type="text" name="sales_donate" id="sales_donate" value="{$detail.sales_donate}" autocomplete="off" style="width:360px;" >
                                            </td>
                                        </tr>

                                        <tr>
                                            <td class="td_left">营业时间</td>
                                            <td style="text-align: left">
                                        <foreach name="weeks" key="key" item="row"> 
                                            <input type="checkbox" name="day[]"  autocomplete="off" value="{$key+1|getPageKey}" {$detail.weeks|getChecked=###,$key+1}>星期{$row}
                                        </foreach>
                                        </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left"></td>
                                            <td style="text-align: left" id="td_business_time">
                                                <p class="green">全选择0代表24小时营业</p>
                                                <span style="display: inline-block;width:75px;">开始时间：</span>
                                                    <select autocomplete="off" id="startHour">
                                                        <foreach name="hours" item="row">
                                                            <option value="{$row}" {$row|getbusiness_timeExplode=###,$detail['business_time'],0}>{$row}</option>
                                                        </foreach>
                                                    </select>
                                                    <select autocomplete="off" id="startMinute">
                                                        <foreach name="minutes" item="row">
                                                            <option value="{$row}" {$row|getbusiness_timeExplode=###,$detail['business_time'],1}>{$row}</option>
                                                        </foreach>
                                                    </select>
                                                <span style="display: inline-block;width:75px;">结束时间：</span>
                                                    <select autocomplete="off" id="endHour">
                                                        <foreach name="hours" item="row">
                                                            <option value="{$row}" {$row|getbusiness_timeExplode=###,$detail['business_time'],2}>{$row}</option>
                                                        </foreach>
                                                    </select>
                                                    <select autocomplete="off" id="endMinute">
                                                        <foreach name="minutes" item="row">
                                                            <option value="{$row}" {$row|getbusiness_timeExplode=###,$detail['business_time'],3}>{$row}</option>
                                                        </foreach>
                                                    </select>
                                                <a onclick="addTimes($(this))">+增加时间段</a>

                                                <p style="margin:5px  0 0;<if condition='$detail.business_time_start2 gt 0'>display: block<else/>display: none</if>" id="addTimes">
                                                    <span style="display: inline-block;width:75px;">开始时间2：</span>
                                                        <select autocomplete="off" id="startHour2">
                                                            <foreach name="hours" item="row" >
                                                                <option value="{$row}" {$row|getbusiness_timeExplode=###,$detail['business_time'],4}>{$row}</option>
                                                            </foreach>
                                                        </select>
                                                        <select autocomplete="off" id="startMinute2">
                                                            <foreach name="minutes" item="row">
                                                                <option value="{$row}" {$row|getbusiness_timeExplode=###,$detail['business_time'],5}>{$row}</option>
                                                            </foreach>
                                                        </select>
                                                    <span style="display: inline-block;width:75px;">结束时间2：</span>
                                                        <select autocomplete="off" id="endHour2">
                                                            <foreach name="hours" item="row">
                                                                <option value="{$row}" {$row|getbusiness_timeExplode=###,$detail['business_time'],6}>{$row}</option>
                                                            </foreach>
                                                        </select>
                                                        <select autocomplete="off" id="endMinute2">
                                                            <foreach name="minutes" item="row">
                                                                <option value="{$row}" {$row|getbusiness_timeExplode=###,$detail['business_time'],7}>{$row}</option>
                                                            </foreach>
                                                        </select>
                                                </p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">团购送餐时间</td>
                                            <td style="text-align: left">
                                        <foreach name="sendtimeArr" key="key" item="row"> 
                                            <input type="checkbox" name="sendtimes[]"  autocomplete="off"
                                                   value="{$key}" {$detail.sendtimes|getChecked=###,$key}>{$row}
                                        </foreach>
                                        </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">平均送餐时间:</td>
                                            <td>
                                                <input name="sendtime" type="text" class="common_txt" style="width:120px;"value="{$detail.sendtime}" autocomplete="off" /> 分钟
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">配送费:</td>
                                            <td>
                                                <input name="sendprice" type="text" class="common_txt" style="width:120px;"value="{$detail.sendprice}" autocomplete="off" /> 元
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">起送价:</td>
                                            <td>
                                                <input name="startprice" type="text" class="common_txt" style="width:120px;" value="{$detail.startprice}" autocomplete="off" /> 元
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">是否开启:</td>
                                            <td>
                                                <label><input type="radio" name="is_check" value="0" autocomplete="off" 
                                                              <if condition="$detail.is_check eq 0">checked</if>> 否</label>
                                                <label><input type="radio" name="is_check" value="1" autocomplete="off" 
                                                              <if condition="$detail.is_check eq 1">checked</if>> 是</label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">排序:</td>
                                            <td>
                                                <input name="ord" type="text" class="common_txt" value="{$detail.ord}" autocomplete="off" />
                                            </td>
                                        </tr>


                                        <tr>
                                            <td class="td_left">关键字:</td>
                                            <td>
                                                <input name="keywords" type="text" class="common_txt" value="{$detail.keywords}" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">描述:</td>
                                            <td>
                                                <textarea  name="description" style="width:410px;height:50px;">{$detail.description}</textarea>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left"></td>
                                            <td>
                                    <input name="circles" type="hidden"  value="{$detail.circles}"/>
                                    <input name="business_time" id="business_time"type="hidden"  value="{$detail.business_time}"/>
                                                <input type='hidden' name='id' value='{$Think.get.id}'/>
                                                <button class="btn btn-info btn-sm" type="submit">
                                                    <i class="icon-ok bigger-110 "></i>
                                                    保 存
                                                </button>
                                                <button class="btn btn-sm reset" type="button" onclick="goUrl(-1)">
                                                    <i class="icon-undo bigger-110"></i>
                                                    返 回
                                                </button>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <include file="Public:setting" />
    </div>
</div>
<include file="Public:foot" />